/**
 * JAVACC DEMO 1.0
 */
package com.apache.info.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.info.entity.PubMetadata;
import com.apache.info.entity.PubSortInfo;
import com.apache.info.manager.PubMetadataManager;
import com.apache.info.manager.PubSortInfoManager;
import com.apache.tools.StrUtil;

import java.util.List;

/**
 * description:  获取定义的表主键元数信息
 *
 * @author Hou Dayu 创建时间：2016-9-1
 */
public class MetadataPrimarykeyPluginImpl implements PluginConnector {

	private PubMetadataManager pubMetadataManager;
	private PubSortInfoManager pubSortInfoManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.
	 *
	 * @see PluginConnector#execute(ParamsVo)
	 */
	public Object execute(ParamsVo arg0) throws Exception {
		ResultEntity entity = new ResultEntity();
		entity.setResult("true");
		String sortCode = String.valueOf(arg0.getParams("sortCode"));
		ParamsVo pvo = new ParamsVo();
		pvo.setInfoId(sortCode);
		String sysName = String.valueOf(arg0.getParams("sysName"));
		pvo.setParams("sysName", StrUtil.doNull(sysName, "plateform"));
		pvo.setMethodKey("BySortCode");
		PubSortInfo info = (PubSortInfo) pubSortInfoManager.getInfoById(pvo);
		if (info == null) {
			entity.setMessage("没有获取到表信息");
			return entity;
		}
		PubMetadata metadata = new PubMetadata();
		metadata.setSortId(sortCode);
		metadata.setDataRestrict("1");
		ParamsVo<PubMetadata> vo = new ParamsVo<PubMetadata>();
		vo.setObj(metadata);
		List<PubMetadata> list = pubMetadataManager.getList(vo);
		if (!Validator.isEmpty(list)) {
			entity.setEntity(list.get(0));
		}
		entity.setMessage("查询成功");
		return entity;
	}

	public void setPubMetadataManager(PubMetadataManager pubMetadataManager) {
		this.pubMetadataManager = pubMetadataManager;
	}

	public void setPubSortInfoManager(PubSortInfoManager pubSortInfoManager) {
		this.pubSortInfoManager = pubSortInfoManager;
	}
}
